package edu.rmit.service.impl;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;

import edu.rmit.dao.IMessageDAO;
import edu.rmit.dao.impl.MessageDAOImpl;
import edu.rmit.domain.Message;
import edu.rmit.service.IMessageService;

/**
 * This class implement the message operation. Like add one message, delete one
 * message, and get one group's message.
 * 
 * @author Joey George
 * @version 1.0
 */
@SuppressWarnings("serial")
public class MessageServiceImpl extends UnicastRemoteObject implements IMessageService{
	
	/**
	 * This instance can be manipulated to implement the database opertion.
	 */
	private IMessageDAO messageDAO;
	
	/**
	 * The constructor to initialize a database operation instance.
	 * @throws RemoteException
	 */
	public MessageServiceImpl() throws RemoteException{
		messageDAO = new MessageDAOImpl();
	}
	
	/**
	 * This method implement to insert an message.
	 * 
	 * @param groupId
	 *            The group id which this message belongs to.
	 * @param content
	 *            The content of this message.
	 * @param userName
	 *            The user name who want to add a message.
	 */
	@Override
	public void addMessage(int groupId, String content, String userName)
			throws RemoteException {
		messageDAO.addMessage(groupId, content, userName);
	}

	/**
	 * This method implement to delete an message.
	 * 
	 * @param messageId
	 *            The message id which you want to delete.
	 */
	@Override
	public void deleteMessage(int messageId) throws RemoteException {
		messageDAO.deleteMessage(messageId);
	}

	/**
	 * This method implement to get all the message which belongs to a
	 * particular group.
	 * 
	 * @param groupId
	 *            The group id which contains all the information.
	 * @return The messages which belongs to this group.
	 */
	@Override
	public List<Message> getMessages(int groupId) throws RemoteException {
		return messageDAO.getMessages(groupId);
	}

}
